//
//  demo1.swift
//  foundationDemo
//
//  Created by Zhang Zhang on 16/6/20.
//  Copyright © 2016年 HNA. All rights reserved.
//

import Foundation
import UIKit
import CoreLocation
func test1_1(){
    let ng = NSRange(location: 3,length: 5)
    print("ng is \(ng)")
}
func test1_2(){
    let np = CGPointMake(10, 15);
    print("np is \(np)")
}
func test1_3(){
    let ns = CGSizeMake(10, 15);
    print("ns is \(ns)")
}
func test1_4(){
    let nr = CGRectMake(10, 5, 100, 200);
    print("nr is \(nr)")
}




func test2_1(){
    let date = NSDate()
    print("date is \(date)")
}
func test2_2(){
    let dateFuture = NSDate.distantFuture()
    print("dateFuture is \(dateFuture)")
}
func test2_3(){
    let date1 = NSDate()
    let dateFuture = NSDate.distantFuture()
    let date2Since = dateFuture.timeIntervalSinceDate(date1)
    print("date2Since is \(date2Since)")
}
func test2_4(){
    let date1 = NSDate()
    let dateFuture = NSDate.distantFuture()
    let date2early = dateFuture.earlierDate(date1)
    print("date2early is \(date2early)")
}
func test2_5(){
    let date1 = NSDate();
    let datef = NSDateFormatter()
    datef.dateFormat="yy-MM-dd HH:mm:ss";
    let str = datef.stringFromDate(date1)
    print("日期格式化 is \(str)")
}
func test2_6(){
    let datef = NSDateFormatter()
    let date = datef.dateFromString("2016-06-11 11:11:11")
    print("字符串转日期 is \(date)")
}

func test3_1(){
    let str:String = "abc"
    print("hello,\(str.uppercaseString)")
    print("hello,\(str.lowercaseString)")
    print("hello,\(str.capitalizedString)")
    
    print(str.hasPrefix("ab"))
    print(str.hasPrefix("abc"))
    
    let string = "abcs" as NSString
    
    
    let range = string.rangeOfString("E")
    
    if(range.location==NSNotFound){
        print("not found")
    }
    
    let str1:NSString = "abcdefg"
    print(str1.substringToIndex(3))
    print(str1.substringFromIndex(3))
    print(str1.substringWithRange(NSMakeRange(2, 3)))
    
    let str2:NSString = "a.vvc.ew.qweq"
    let array:NSArray = str2.componentsSeparatedByString(".")
    print(array)
    
    let str3:NSString = "123"
    print(str3.intValue)
    
    let str4:NSString = "hello world,世界你好！"
    print(str4.length)
    print(str4.characterAtIndex(3))
    print(str4.UTF8String)
    
}
func test4_1(){
    let str:NSMutableString = NSMutableString()
    str.setString("hello")
    
    print(str.stringByAppendingString("aaa"))
    print(str.stringByAppendingFormat("hello %@ %i %f", "world",1,0.5))
    
    let range:NSRange = str.rangeOfString("ell")
    str.replaceCharactersInRange(range, withString: "aaa")
    print(str)
    
    str.insertString("lll", atIndex: 1)
    print(str)
    
    str.deleteCharactersInRange(str.rangeOfString("lll"))
    print(str)
}

func test5_1(){
    let obj = NSObject()
    let array:NSArray = ["abc",obj,"cde","opq",25]
    print(array.count)
    print(array.containsObject("cde"))
    print(array.lastObject)
    print(array.indexOfObject("cde"))
    
    //for(var i = 0; i < array.count;i++)
    for i:Int in 0 ... array.count-1 {
        print("method is \(array[i])");
    }
    for obj in array {
        print("method1 is \(obj)");
    }
    
    var array2:NSArray=array.arrayByAddingObject("7")
    print(array2)
    
    array2 = array2.arrayByAddingObjectsFromArray(["lal","lol",3232])
    print(array2)
    
}
func test6_1(){
    let number:NSNumber = NSNumber(char: "a".cStringUsingEncoding(NSUTF8StringEncoding)[0])
    let char=number.charValue
   
    let number1:NSNumber = NSNumber(bool: true)
    let bool = number1.boolValue
    print(char)
    print(bool)
    
    
    
    let point:CGPoint = CGPointMake(10, 20)
    let value = NSValue(CGPoint: point)
    let array = NSArray(object: value)
    print(array)
    let value2 = array.lastObject
    
    
    
}

//func ui(){
//
//    
//    let label = UILabel(frame:CGRect(origin: CGPointMake(10.0, 50.0), size: CGSizeMake(150,50)))//let 是Swift 表示常量的关键字
//    label.text = "This is a Label"
//    UIView.addSubview(label)
//}